package logic

import (
	"context"
	"fmt"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/mooc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfoLogic {
	return &GoodsInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsInfoLogic) GoodsInfo(in *mooc.GoodsInfoRequest) (*mooc.GoodsInfoResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	err := g.FindGoods(in.GoodsId)
	if err != nil {
		logx.Error("商品详情查询失败")
		return nil, fmt.Errorf("商品详情查询失败")
	}

	return &mooc.GoodsInfoResponse{
		GoodsName:  g.GoodsName,
		GoodsPrice: float32(g.GoodsPrice),
	}, nil
}
